/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Oct 4, 2013  3:02:46 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : sap.business.commons
 * File Name : SapBapi.java
 * TODO
 */
package sap.business.commons;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;

import sap.jco.client.Connection;
import sun.util.logging.resources.logging;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Oct 4, 2013 : 3:02:46 PM 
 * CreateBy=Chatree Siangklom
 * 
 * SapBapi
 * TODO
 */
public class SapBapi {
	
	
	private static final Logger logging = LoggerFactory
			.getLogger(SapBapi.class);
	
	private String sap_bapi;
	private Connection jcoConnection;
	
	
	
	/**
	 * @return the jcoConnection
	 * Date =Jan 15, 2014 : 3:36:36 PM 
	 * CreateBy=Chatree Siangklom
	 * SapBapi.java Connection
	 * TODO
	 */
	public Connection getJcoConnection() {
		return jcoConnection;
	}

	/**
	 * @param jcoConnection the jcoConnection to set
	 * Date =Jan 15, 2014 : 3:36:36 PM 
	 * CreateBy=Chatree Siangklom
	 *  SapBapi.java Connection
	 * TODO
	 */
	public void setJcoConnection(Connection jcoConnection) {
		this.jcoConnection = jcoConnection;
	}

	/**
	 * @param sap_bapi the sap_bapi to set
	 * Date =Jan 15, 2014 : 3:36:36 PM 
	 * CreateBy=Chatree Siangklom
	 *  SapBapi.java String
	 * TODO
	 */
	public void setSap_bapi(String sap_bapi) {
		this.sap_bapi = sap_bapi;
	}

	/**
	 * @param jCoFunction the jCoFunction to set
	 * Date =Jan 15, 2014 : 3:36:36 PM 
	 * CreateBy=Chatree Siangklom
	 *  SapBapi.java JCoFunction
	 * TODO
	 */
	public void setjCoFunction(JCoFunction jCoFunction) {
		this.jCoFunction = jCoFunction;
	}

	/**
	 * @return the sap_bapi
	 * Date =Oct 4, 2013 : 3:05:08 PM 
	 * CreateBy=Chatree Siangklom
	 * SapBapi.java String
	 * TODO
	 */
	public String getSap_bapi() {
		return sap_bapi;
	}

	/**
	 * Date =Oct 4, 2013 : 3:02:46 PM 
	 * CreateBy=Chatree Siangklom
	 * SapBapi
	 * TODO
	 */
	public SapBapi(String sap_bapi) {
		this.sap_bapi = sap_bapi;
	}
	
	/**
	 * 
	 * Date =Oct 4, 2013 : 5:08:38 PM 
	 * CreateBy=Chatree Siangklom
	 * SapBapi
	 * TODO
	 * @param sap_bapi
	 * @param jcoConnection
	 */
	public SapBapi(String sap_bapi, Connection jcoConnection) {
		setJcoConnection(jcoConnection);
		setSap_bapi(sap_bapi);
	}
	
	/**
	 * 
	 * Date =Oct 4, 2013 : 5:08:35 PM 
	 * CreateBy=Chatree Siangklom
	 * JCoFunction
	 * TODO
	 * @return
	 * @throws JCoException
	 * @throws IOException
	 */
	public JCoFunction getJCoFunction() throws JCoException, IOException, Exception {
		if(jcoConnection == null) 
			throw new Exception("SAP Connection is null !!!");
		
		logging.info("JCOFunction Name=" + getSap_bapi());
		
		jCoFunction = jcoConnection.getJCoFunction(getSap_bapi());
		if(jCoFunction == null)
			throw new Exception("SAP Function is null !!!");
		
		return jCoFunction;
	}
	
	private JCoFunction jCoFunction;

	/**
	 * @return the jCoFunction
	 * Date =Oct 4, 2013 : 5:55:45 PM 
	 * CreateBy=Chatree Siangklom
	 * SapBapi.java JCoFunction
	 * TODO
	 */
	public JCoFunction getjCoFunction() {
		return jCoFunction;
	}
}
